chrome.runtime.onMessage.addListener((request) => {
  // if (request.type === 'COUNT') {
  //   aa = true
    
  // }
})

const send = (hours=18,minutes =0)=>{
  console.log('send',hours,minutes)
  const now = new Date()
  if(now.getHours() == hours && (now.getMinutes() - minutes>=0) && (now.getMinutes() - minutes<=2)){
    chrome.notifications.create({
      type: 'basic',
      iconUrl: 'img/logo-16.png',
      title: '下班了',
      message: '记得打卡'
    }, function(notificationId) {
      console.log('通知已创建，ID:', notificationId);
    }
    )
  }
}

setInterval(()=>{
  chrome.storage.sync.get(['setting'], (result) => {
    if(result?.setting){
      const resData = JSON.parse(result.setting)
      let hours = resData.closingTime.split(':')[0]
      let minutes = resData.closingTime.split(':')[1]
      send(Number(hours),Number(minutes))
    }else{
      send()
    }
  })
}, 60000)
